package com.skp.shaphan.ui.dialogs;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;

import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JTextField;

import com.skp.shaphan.ShaphanApp;
import com.skp.shaphan.ui.buttons.ButtonsPane;
import com.skp.shaphan.ui.buttons.DialogCancelButton;
import com.skp.shaphan.ui.buttons.ImportOkButton;

public class ImportDialog extends JDialog {
	private JComboBox saveAs;
	private JTextField path;
	private JTextField tableName;

	public ImportDialog() {
		super(ShaphanApp.getMainWindow(), "Export");

		this.setLayout(new GridBagLayout());
		int row = 0;

		this.add(new JLabel("Source:"), new GridBagConstraints(0, row, 1, 1, 0.0, 1.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 5, 5));
		String[] options = {"File", "Clipboard"};
		saveAs = new JComboBox(options);
		this.add(saveAs, new GridBagConstraints(1, row++, 1, 1, 1.0, 1.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 5, 5));
		
		this.add(new JLabel("Import Path:"), new GridBagConstraints(0, row, 1, 1, 0.0, 1.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 5, 5));
		path = new JTextField();
		this.add(path, new GridBagConstraints(1, row++, 1, 1, 1.0, 1.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 5, 5));
		
		this.add(new JLabel("Target Table:"), new GridBagConstraints(0, row, 1, 1, 0.0, 1.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 5, 5));
		tableName = new JTextField();
		this.add(tableName, new GridBagConstraints(1, row++, 1, 1, 1.0, 1.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 5, 5));
		
		this.add(new ButtonsPane(new DialogCancelButton(this), new ImportOkButton(this)), new GridBagConstraints(0, row++, 2, 1, 1.0, 1.0, GridBagConstraints.EAST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 5, 5));
		this.pack();
	}
	
	public String getInputPath() {
		return path.getText();
	}
	
	public boolean isFileExport() {
		if(saveAs.getSelectedIndex() == 0) {
			return true;
		}
		return false;
	}
	
	public String getTablename() {
		return tableName.getText();
	}
}
